import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  CreateDateColumn,
  Index,
  JoinColumn,
} from 'typeorm';
import { User } from './user.entity';
import { Video } from './video.entity';

@Entity()
@Index(['user', 'createdAt']) // 复合索引优化查询
export class VideoHistory {
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToOne(() => User, (user) => user.viewHistories)
  @JoinColumn({ name: 'user_id' })
  user: User;

  @ManyToOne(() => Video, (video) => video.viewHistories)
  @JoinColumn({ name: 'video_id' })
  video: Video;

  @CreateDateColumn({
    type: 'datetime',
    comment: '浏览时间',
  })
  createdAt: Date;

  // view-history.entity.ts
  @Column({ default: 0 })
  is_deleted: number;
  history: Promise<User>;
}
